import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { Website } from './website.entity';

@Entity('page_views')
export class PageView {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => Website, website => website.pageViews)
  @JoinColumn({ name: 'website_id' })
  website: Website;

  @Column()
  websiteId: number;

  @Column()
  url: string;

  @Column({ nullable: true })
  title: string;

  @Column({ nullable: true })
  referrer: string;

  @Column({ nullable: true })
  userAgent: string;

  @Column({ nullable: true })
  ip: string;

  @Column({ nullable: true })
  country: string;

  @Column({ nullable: true })
  city: string;

  @Column({ nullable: true })
  browser: string;

  @Column({ nullable: true })
  os: string;

  @Column({ nullable: true })
  device: string;

  @Column({ nullable: true })
  screenSize: string;

  @Column({ nullable: true })
  language: string;

  @Column({ nullable: true, type: 'json' })
  customData: Record<string, any>;

  @Column({ default: 0 })
  timeOnPage: number;

  @Column({ default: false })
  isUnique: boolean;

  @Column({ nullable: true })
  sessionId: string;

  @CreateDateColumn()
  createdAt: Date;
} 